import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { generateRoutes } from "./routes/generateRoutes";
import NotFound from "./components/notFound";
// 递归渲染嵌套路由的辅助函数
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const renderRoutes = (routes: any[]) => {
  return routes.map((route, index) => (
    <Route key={index} path={route.path} element={route.element}>
      {route.children && renderRoutes(route.children)}
    </Route>
  ));
};

const App: React.FC = () => {
  const routes = generateRoutes();

  return (
    <Router>
      <Routes>
        {renderRoutes(routes)}
        <Route path="*" element={<NotFound />} />
      </Routes>
    </Router>
  );
};

export default App;
